
import type { MaProTableColumns, MaProTableExpose } from '@mineadmin/pro-table'
import type { UserVo } from '~/base/api/user.ts'
import type { UseDialogExpose } from '@/hooks/useDialog.ts'

import defaultAvatar from '@/assets/images/defaultAvatar.jpg'
import { ElTag } from 'element-plus'
import { useMessage } from '@/hooks/useMessage.ts'
import { deleteByIds, resetPassword } from '~/base/api/user.ts'
import { ResultCode } from '@/utils/ResultCode.ts'
import hasAuth from '@/utils/permission/hasAuth.ts'

export default function getTableColumns(dialog: UseDialogExpose, formRef: any, t: any): MaProTableColumns[] {
  const dictStore = useDictStore()
  const msg = useMessage()
  return [
    // 展开列
    {width: '80px', type: 'expand',
      cellRender: ({ row }) => (
        <div class="flex-center">
          {row.id}
        </div>
      )
    },
    // 排序列
    {width: '80px', type: 'sort'},
    // 多选列
    { type: 'selection'},
    // 索引序号列
    // { type: 'index' },
    // 普通列
    { label: '商品ID', prop: 'id' },
    { label: '商品图', prop: 'avatar', width: '80px',
      cellRender: ({ row }) => (
        <div class="flex-center">
          <el-image style="width: 50px; height: 50px" src={(row.avatar === '' || !row.avatar) ? defaultAvatar : row.avatar} alt={row.username} />
        </div>
      ),
    },
    { label: '商品名称', prop: 'nickname' ,width: '400px'},
    { label:'来源', prop: 'user_type',
      cellRender: ({ row }) => (
        <ElTag type="success">
          直营
        </ElTag>
      ),
    },
    { label:'状态', prop: 'user_type',
      cellRender: ({ row }) => (
        <ElTag type="success">
          销售
        </ElTag>
      ),
    },
    { label: '定价成本', prop: 'phone' },
    { label: '商品售价', prop: 'phone' },
    { label: '库存', prop: 'phone' },
    // { label: '类型', prop: 'phone' },
    // 操作列
    {
      type: 'operation',
      label:'操作',
      fixed: 'right',
      width: '180px',
      operationConfigure: {
        type: 'tile',
        actions: [
          {
            name: 'copy',
            icon: 'material-symbols:content-copy',
            text: '复制',
            onClick: ({ row }) => {
              dialog.setTitle('新增')
              dialog.open({ formType: 'copy', data: row })
            },
          },
          {
            name: 'edit',
            icon: 'material-symbols:person-edit',
            text: '编辑',
            onClick: ({ row }) => {
              dialog.setTitle('编辑')
              dialog.open({ formType: 'edit', data: row })
            },
          },
          {
            name: 'del',
            icon: 'mdi:delete',
            text: '删除',
            onClick: ({ row }, proxy: MaProTableExpose) => {
              msg.delConfirm(t('crud.delDataMessage')).then(async () => {
                const response = await deleteByIds([row.id])
                if (response.code === ResultCode.SUCCESS) {
                  msg.success(t('crud.delSuccess'))
                  proxy.refresh()
                }
              })
            },
          },


        ],
      },
    },
  ]
}
